<template>
  <!-- 今日登记患者 -->
  <section>
    <div class="form-tool" style="align-items: center;">
      <div>
        <el-form :inline="true" @submit.native.prevent="getData(-1)">
          <el-form-item prop="deptId">
            <deptSearch v-model="form.deptId" @change="onChangeDeptTody"></deptSearch>
          </el-form-item>
          <el-form-item prop="doctorId">
            <!-- <el-select v-model="form.doctorId" :remote-method="getDoctorList" filterable remote clearable @clear="getDoctorList">
                  <el-option v-for="(item,index) in doctorArray" :key="index" :value="item.id" :label="item.trueName"></el-option>
                </el-select> -->
            <doctorSearch ref="doctorSearchToday" v-model="form.doctorId" :deptId="form.deptId"></doctorSearch>
          </el-form-item>
          <el-form-item>
            <patientSearch v-model="form.patientId"></patientSearch>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" native-type="submit" circle></el-button>
            <el-button type="danger" icon="el-icon-refresh" @click="getData(-1)">刷新</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <el-row :gutter="20">
      <el-col v-for="(item,index) in tableList" :key="index" :xs="24" :sm="24" :md="24" :lg="12" :xl="8" class="reserve-user-list">
        <div :class="['card-box',classToName(item.status) ]">
          <div class="card-nr">
            <div>
              <img v-if="!item.patientInfo.head" src="@/img/unknown-avatar.png" class="head-img" alt="" style="width:50px;height:50px;">
              <img v-else :src="item.patientInfo.head|imageUrl" class="head-img" alt="" style="width:50px;height:50px;">
            </div>
            <div style="overflow: hidden;">
              <p class="overflow-omit">
                <span style="font-size:18px;">{{item.patientInfo.name}} </span>
                &nbsp;
                <span>（{{item.patientInfo.sex|toSex}}&nbsp;<span v-if="item.patientInfo.age>17">{{item.patientInfo.age}}岁</span><span v-else>{{item.patientInfo.birthday|toTimeContrast}}</span>）</span>
              </p>
              <div class="overflow-omit">预约时间：{{item.dateDay}}&nbsp;{{item.startTime}}~{{item.endTime}}</div>
              <div class="overflow-omit">预约：({{item.doctorName}}、{{item.deptName}}、{{item.roomName}}、{{item.registerName}})</div>
              <div class="overflow-omit">预约内容：{{item.registerContent}}</div>
              <div class="overflow-omit">创建时间：{{item.gmtCreate}}</div>
            </div>
          </div>
          <!-- <div class="card-footer">
            <div @click="onToUserDetail(item)">查看</div>
            <div v-if="item.status==1" @click="onArrive(item,index)">到诊</div>
            <div v-if="item.status==1" @click="onCancel(item,index)">取消登记</div>
          </div> -->
          <div class="zt-box">{{item.status|changeAssist(triageStatusArray)}}</div>
          <div v-if="item.patientInfo.levelId" class="vip-box">
            <el-tooltip :content="item.patientInfo.levelName" placement="top">
              <img src="@/img/icon-vip.png" alt="">
            </el-tooltip>
          </div>
        </div>
      </el-col>
    </el-row>
    <div v-if="tableList.length == 0" style="color:#999;padding:10px 0;text-align:center;">
      <i class="iconfont iconwushuju" style="font-size:40px;"></i>
      <div>暂无数据</div>
    </div>
    <br>
    <pager v-model="pager" @change-pagenum="getData"></pager>

  </section>
</template>
<script>
export default {
  props: ["qxBtns"],
  components: {
    deptSearch: () => import("@/pages/_com/deptSearch.vue"),
    doctorSearch: () => import("@/pages/_com/doctorSearch.vue"),
    patientSearch: () => import("@/pages/_com/patientSearch.vue")
  },
  data() {
    return {
      curItem: {
        patientInfo: {
          patientId: ""
        }
      },
      form: {
        patientId: "",
        doctorId: "",
        status: "",
        dateDayStart: "",
        dateDayEnd: ""
      },
      pager: { pageSize: 9, pageNum: 1, total: 0 },
      tableList: [],
      //预约状态
      triageStatusArray: []
    };
  },
  async mounted() {
    let th = this;
    let date = new Date();
    th.triageStatusArray = await th.getCommonConfigByKey("预约状态");
    th.form.dateDayStart = th.$utils.FormatTime("yyyy-MM-dd", date.getTime());
    th.form.dateDayEnd = th.$utils.FormatTime("yyyy-MM-dd", date.getTime());
    th.getData();
  },
  methods: {
    onToUserDetail(obj) {
      let th = this;
      if (th.verifyUrl("/page/patientList")) {
        let url = "/page/userDetail";
        let j = {
          id: th.jiaMi(obj.patientInfo.patientId)
        };
        th.addNavMenu("病人库", url, "userDetail");
        th.$router.push({
          path: url,
          query: th.getUrlToken(j)
        });
      }
    },
    //到诊
    onArrive(obj, index) {
      const th = this;
      // th.curItem = obj;
      th.$confirm("确定此患者已到诊吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(() => {
          th.showLoading();
          let j = {
            status: 6,
            id: obj.id
          };
          th.$api
            .updateRegisterRecord(j)
            .then(res => {
              if (res.executed) {
                th.$message.success("更新完成");
                // obj.status = j.status;
                th.tableList.splice(index, 1);
              } else {
                th.$message.error(res.message);
              }
              th.showLoading(false);
            })
            .catch(res => {
              th.showLoading(false);
            });
        })
        .catch(() => {});
    },
    //取消预约
    onCancel(obj, index) {
      let th = this;
      if (!th.qxBtns.del) {
        th.$message.warning("权限不足");
        return;
      }
      if (obj.status != 1) {
        th.$message.warning("无法取消");
        return;
      }
      th.$confirm(`确定取消吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(() => {
          let j = {
            id: obj.id,
            cancelDesc: "工作人员取消"
          };
          th.showLoading();
          th.$api.registerCancelOrder(j).then(res => {
            if (res.executed) {
              th.$message.success("取消完成");
              th.tableList.splice(index, 1);
            } else {
              th.showLoading(false);
              th.$message.error(res.message);
            }
          });
        })
        .catch(() => {
          th.showLoading(false);
        });
    },
    getData(type) {
      let th = this;
      if (type == -1) {
        th.pager.pageNum = 1;
        th.pager.total = 0;
      }
      let j = {};
      Object.assign(j, th.form, th.pager);
      th.$api.getRegisterListInfo(j).then(res => {
        if (res.executed) {
          th.tableList = res.dataBody.list;
          th.pager.total = res.dataBody.total;
        }
      });
    },
    //判断类名
    classToName(type) {
      switch (type) {
        case 1:
          return "bg-yjz";
          break;
        case 2:
          return "bg-sy";
          break;
        case 3:
          return "bg-hong";
          break;
        case 4:
          return "bg-yqx";
          break;
        case 5:
          return "bg-jzz";
          break;
        default:
          return "bg-dfz";
          break;
      }
    },
    //今日患者科室选择
    onChangeDeptTody(value) {
      let th = this;
      th.form.doctorId = "";
      th.$nextTick(function() {
        th.$refs["doctorSearchToday"].getData();
      });
    }
  }
};
</script>
<style lang="scss" scoped>
@import "../../_css/reserve.scss";
</style>